package com.mlk.waste.controller;

import com.mlk.core.util.ServerResponse;
import com.mlk.waste.po.EngWasteTypeTree;
import com.mlk.waste.po.EngWasteTypeTreePrice;
import com.mlk.waste.service.WasteTypeTreeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 最新的废品类型为树形的结构
 */
@Controller
@RequestMapping("/eng/waste/type/tree")
public class WasteTypeTreeController {

    @Resource
    private WasteTypeTreeService wasteTypeTreeService;

    /**
     * 返回废品类型首页
     * @return
     */
    @RequestMapping("index")
    public String index(){
        return "waste/wasteTree";
    }


    /**
     * 添加主分类
     * @return
     */
    @ResponseBody
    @RequestMapping("addMainType")
    public ServerResponse addMainType(String name,String unit){
        return this.wasteTypeTreeService.addMainType(name,unit);
    }

    /**
     * 查询所有的节点
     * @return
     */
    @ResponseBody
    @RequestMapping("queryAllNode")
    public ServerResponse queryAllNode(){
        return this.wasteTypeTreeService.queryAllNode();
    }

    // 修改节点的名称
    @RequestMapping("editTypeName")
    @ResponseBody
    public ServerResponse editTypeName(EngWasteTypeTree tree){
        return this.wasteTypeTreeService.editTypeName(tree);
    }

    /**
     * 添加子级
     * @return
     */
    @RequestMapping("addSon")
    @ResponseBody
    public ServerResponse addSon(EngWasteTypeTree tree){
        return this.wasteTypeTreeService.addSon(tree);
    }


    /**
     * 获取一个类型的价格信息
     * @return
     */
    @RequestMapping("getAllPrice")
    @ResponseBody
    public ServerResponse getAllPrice(Integer id){
        return  this.wasteTypeTreeService.getAllPrice(id);
    }


    /**
     * 修改类型的价格信息
     * @return
     */
    @ResponseBody
    @RequestMapping("editTypePrice")
    public ServerResponse editTypePrice(@RequestBody List<EngWasteTypeTreePrice> lists,Integer typeId){
        return this.wasteTypeTreeService.editTypePrice(lists,typeId);
    }

    // 新增 的方法 结束 ......



    /**
     * 打开或者关闭
     * @return
     */
    @ResponseBody
    @RequestMapping("openOrClose")
    public ServerResponse openOrClose(EngWasteTypeTree tree){
        return this.wasteTypeTreeService.openOrClose(tree);
    }

    /**
     * 修改主分类的计量单位
     * @param tree
     * @return
     */
    @ResponseBody
    @RequestMapping("editUnit")
    public ServerResponse editUnit(EngWasteTypeTree tree){
        return this.wasteTypeTreeService.editUnit(tree);
    }

    /**
     * 删除节点
     * @return
     */
    @RequestMapping("delTreeNode")
    @ResponseBody
    public ServerResponse delTreeNode(Integer id){
        return this.wasteTypeTreeService.delTreeNode(id);
    }

    /**
     * 交换
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("swap")
    public ServerResponse swap(Integer id,Integer sourceId){
        return this.wasteTypeTreeService.swap(id,sourceId);
    }
}
